﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace D20.Entities.Items.Weaponry
{
    /// <summary>
    /// A class representing the damage that can be applied from a weapon or other trauma.
    /// </summary>
    public class Damage
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Damage"/> class.
        /// </summary>
        public Damage()
        {
            DamageDescriptions = new List<DamageDescription>();
        }
        /// <summary>
        /// Gets the damage descriptions.
        /// </summary>
        /// <value>The damage descriptions.</value>
        public List<DamageDescription> DamageDescriptions { get; private set; }
    }

    /// <summary>
    /// A description of damage.
    /// </summary>
    public struct DamageDescription
    {
        #region Equals etc
        /// <summary>
        /// Indicates whether this instance and a specified object are equal.
        /// </summary>
        /// <param name="obj">Another object to compare to.</param>
        /// <returns>
        /// true if <paramref name="obj"/> and this instance are the same type and represent the same value; otherwise, false.
        /// </returns>
        public override bool Equals(object obj)
        {
            if (obj is DamageDescription)
            {
                DamageDescription d = (DamageDescription)obj;
                return DamageType == d.DamageType && Effectiveness == d.Effectiveness;
            }
            return false;
        }
        /// <summary>
        /// Returns the hash code for this instance.
        /// </summary>
        /// <returns>
        /// A 32-bit signed integer that is the hash code for this instance.
        /// </returns>
        public override int GetHashCode()
        {
            return DamageType.GetHashCode() << 16 ^ Effectiveness.GetHashCode();
        }
        /// <summary>
        /// Implements the operator ==.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator ==(DamageDescription left, DamageDescription right)
        {
            return left.DamageType == right.DamageType && left.Effectiveness == right.Effectiveness;
        }
        /// <summary>
        /// Implements the operator !=.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator !=(DamageDescription left, DamageDescription right)
        {
            return !(left.DamageType == right.DamageType && left.Effectiveness == right.Effectiveness);
        }
        #endregion
        /// <summary>
        /// Gets or sets the type of the damage.
        /// </summary>
        /// <value>The type of the damage.</value>
        public DamageType DamageType { get; set; }
        /// <summary>
        /// Gets or sets the effectiveness.
        /// </summary>
        /// <value>The effectiveness.</value>
        public DiceRoll Effectiveness { get; set; }
    }

    /// <summary>
    /// The type of damage.
    /// </summary>
    public enum DamageType
    {
        /// <summary>
        /// Blunt trauma, such as from a club.
        /// </summary>
        Blunt,
        /// <summary>
        /// Penetrating trauma, such as from an arrow.
        /// </summary>
        Penetrating,
        /// <summary>
        /// Cold damage, such as from a blizzard.
        /// </summary>
        Cold,
        /// <summary>
        /// Hot damage, such as from fire.
        /// </summary>
        Hot,
        /// <summary>
        /// Necromancy magic, such as a death spell.
        /// </summary>
        Necromancy,
        /// <summary>
        /// Ground damage, such as from an earthquake.
        /// </summary>
        Ground,
        /// <summary>
        /// Wind damage, such as from a tornado.
        /// </summary>
        Wind,
        /// <summary>
        /// General force magic, such as from a magic missile.
        /// </summary>
        ForceMagic
    }
}
